home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 August: Technology Seed / ADC Seed CD - August 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / Offscreen.cp < prev    next >
Encoding:
Text File  |  1999-05-01  |  2.7 KB  |  141 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Offscreen.cp
  3.  
  4.     Contains:    Class to help with offscreen drawing.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. #include "AppearanceSamplePrefix.h"
  28.  
  29. #include <Appearance.h>
  30. #include "Offscreen.h"
  31.  
  32. Offscreen::Offscreen()
  33. {
  34.     fWorld = nil;
  35.     fSavePort = nil;
  36.     fSaveDevice = nil;
  37.     SetRect( &fBounds, 0, 0, 0, 0 );
  38. }
  39.  
  40. Offscreen::~Offscreen()
  41. {
  42. }
  43.  
  44. void
  45. Offscreen::StartDrawing( const Rect& bounds, Boolean copyDest )
  46. {
  47.     QDErr                err;
  48.     Rect                globalRect;
  49.     ThemeDrawingState    state;
  50.     
  51.     fBounds = bounds;
  52.     
  53.     GetGWorld( &fSavePort, &fSaveDevice );
  54.     
  55.     globalRect = fBounds;
  56.     
  57.     LocalToGlobal( &topLeft( globalRect ) );
  58.     LocalToGlobal( &botRight( globalRect ) );
  59.  
  60.     err = NewGWorld( &fWorld, 0, &globalRect, nil, nil, 0 );
  61.     if ( err == noErr )
  62.     {
  63.         GetThemeDrawingState( &state );
  64.         SetGWorld( fWorld, nil );
  65.         SetOrigin( fBounds.left, fBounds.top );
  66.         SetThemeDrawingState( state, true );
  67.         
  68.         LockPixels( GetGWorldPixMap( fWorld ) );
  69.         EraseRect( &fBounds );
  70.         TextFont( GetPortTextFont( fSavePort ) );
  71.         TextSize( GetPortTextSize( fSavePort ) );
  72.         TextFace( GetPortTextFace( fSavePort ) );
  73.         TextMode( GetPortTextMode( fSavePort ) );
  74.         
  75.         if ( copyDest )
  76.         {
  77.             Rect        portRect;
  78.             
  79.             GetPortBounds( fWorld, &portRect );    
  80.             CopyBits( (BitMap*)*GetPortPixMap( fSavePort ), (BitMap*)*GetPortPixMap( fWorld ),
  81.                 &fBounds, &portRect, srcCopy, nil );
  82.         }
  83.     }
  84.     else
  85.         fWorld = nil; // make sure
  86. }
  87.  
  88. void
  89. Offscreen::EndDrawing()
  90. {
  91.     ThemeDrawingState    state;
  92.       Rect                portRect;
  93.     
  94.     if ( fWorld == nil ) return;
  95.     
  96.     SetOrigin( 0, 0 );
  97.     SetGWorld( fSavePort, fSaveDevice );
  98.  
  99.     GetThemeDrawingState( &state );
  100.     NormalizeThemeDrawingState();
  101.                 
  102.     GetPortBounds( fWorld, &portRect );    
  103.     CopyBits( (BitMap*)*GetPortPixMap( fWorld ), (BitMap*)*GetPortPixMap( fSavePort ),
  104.             &portRect, &fBounds, srcCopy, NULL );
  105.  
  106.     UnlockPixels( GetGWorldPixMap( fWorld ) );
  107.     DisposeGWorld( fWorld );
  108.     
  109.     fWorld = nil;
  110.     
  111.     SetThemeDrawingState( state, true );
  112. }
  113.  
  114. void
  115. Offscreen::EndDrawingAndBlend( const RGBColor& opColor )
  116. {
  117.     ThemeDrawingState    state;
  118.     Rect                portRect;
  119.  
  120.     if ( fWorld == nil ) return;
  121.     
  122.     SetOrigin( 0, 0 );
  123.     SetGWorld( fSavePort, fSaveDevice );
  124.  
  125.     GetThemeDrawingState( &state );
  126.     NormalizeThemeDrawingState();
  127.     
  128.     OpColor( &opColor );
  129.     GetPortBounds( fWorld, &portRect );    
  130.     CopyBits( (BitMap*)*GetPortPixMap( fWorld ), (BitMap*)*GetPortPixMap( fSavePort ),
  131.             &portRect, &fBounds, blend, NULL );
  132.  
  133.     UnlockPixels( GetGWorldPixMap( fWorld ) );
  134.     DisposeGWorld( fWorld );
  135.     
  136.     fWorld = nil;
  137.     
  138.     SetThemeDrawingState( state, true );
  139. }
  140.  
  141.